# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 下午4:07
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : contract_page.py
# @Software: PyCharm

from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
class  ContractPage(BasePage):
    """合同页面"""
    url="/crm/index.php?m=contract"
    contract_add_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")  # 添加合同
    check_locator = (By.LINK_TEXT, "查看")  # 查看
    contract_modify_locator= (By.LINK_TEXT, "编辑")  # 编辑
    check_box_locator = (By.NAME, "contract_id[]")  # 勾选框
    delete_btn_locator = (By.ID, "delete")  # 删除按钮
    condition_one_select_locator = (By.ID, "field")  # 第一个筛选框
    condition_two_select_locator = (By.ID, "condition")  # 第二个筛选框
    search_locator = (By.ID, "search")  # 搜索框
    search_btn_locator = (By.CSS_SELECTOR, "#searchForm > ul > li:nth-child(4) > button")  # 搜索按钮

    my_duty_locator = (By.CSS_SELECTOR, "body > div.container > p > a:nth-child(4)")  # 我负责的
    branch_duty_locator = (By.CSS_SELECTOR, "body > div.container > p > a:nth-child(5)")  # 下属负责的
    today_sign_locator = (By.CSS_SELECTOR, "body > div.container > p > a:nth-child(9)")  # 今日签约
    week_sing_locator = (By.CSS_SELECTOR, "body > div.container > p > a:nth-child(10)")  # 本周签约


    def click_contract_add(self):
        """点击添加合同"""
        self.driver.find_element(*self.contract_add_locator).click()
    def click_contract_modify(self):
        """点击编辑"""
        self.driver.find_element(*self.contract_modify_locator).click()

    def click_check(self):
        """点击查看"""
        self.driver.find_element(*self.check_locator).click()
    def click_check_box(self):
        """勾选合同"""
        self.driver.find_element(*self.check_box_locator).click()
    def click_delete_btn(self):
        """点击删除"""
        self.driver.find_element(*self.delete_btn_locator).click()
    def accept(self):
        """确定弹框"""
        self.driver.switch_to.alert.accept()

    def click_my_duty(self):
        """点击我负责的"""
        self.driver.find_element(*self.my_duty_locator).click()
    def click_branch_duty(self):
        """点击下属负责的"""
        self.driver.find_element(*self.branch_duty_locator).click()
    def click_today_sign(self):
        """点击今日签约"""
        self.driver.find_element(*self.today_sign_locator).click()
    def click_week_sing(self):
        """点击本周签约"""
        self.driver.find_element(*self.week_sing_locator).click()

    def select_condition_one(self,choose_one):
         """第一个筛选框"""
         condition_one_select_element = self.driver.find_element(*self.condition_one_select_locator)
         condition_one_select_obj = Select(condition_one_select_element)
         condition_one_select_obj.select_by_visible_text(choose_one)

    def select_condition_two(self,choose_two):
         """第二个筛选框"""
         condition_two_select_element = self.driver.find_element(*self.condition_two_select_locator)
         condition_two_select_obj = Select(condition_two_select_element)
         condition_two_select_obj.select_by_visible_text(choose_two)

    def input_search_select(self,content):
         """搜索框输入搜索的内容"""
         self.driver.find_element(*self.search_locator).send_keys(content)
    def click_search_btn(self):
        """点击搜索"""
        self.driver.find_element(*self.search_btn_locator).click()
